# 单调栈
def right_bigger(a):
    # 初始栈
    stack=[]
    ans=[-1]*n
    for i in range(n):
        while stack and a[stack[-1]] < a[i]:
            # 记录答案
            ans[stack[-1]]=i+1
            stack.pop()
        stack.append(i)
    for x in ans:
        print(x,end=' ')

def left_bigger(a):
    stack=[]
    ans=[-1]*n
    for i in range(n-1,-1,-1):
        while stack and a[stack[-1]] < a[i]:
            # 记录答案
            ans[stack[-1]] = i + 1
            stack.pop()
        stack.append(i)
    for x in ans:
        print(x, end=' ')

n=int(input())
a=list(map(int,input().split()))

left_bigger(a)
print()
right_bigger(a)